package com.intct.phoenix;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author gufg
 * @since 2025-07-23 09:42
 */
public class JdbcConnectPhoenix {
    public static void main(String[] args) throws Exception {
        // URL
        String url = "jdbc:phoenix:cdh-node:2181:/hbase";

        // 驱动类
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        // 创建连接
        Connection connection = DriverManager.getConnection(url);

        // SQL语句
        String sql = "select \"id\",\"f1\".\"name\" f1_name,DEPT_ID,DEPT_NAME,\"name_1\",f3.\"name\" as f3_name from \"intct82\".\"t5\"";

        /**
         * f1 f2
         * f1.name f1.age
         * f2.name
         */

        // 执行SQL
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        // 执行SQL语句
        ResultSet resultSet = preparedStatement.executeQuery();

        // 打印
        while (resultSet.next()) {

            System.out.println(resultSet.getString("f3_name"));
        }

        // 关闭资源
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
